#author by 得力

#注意：脚本目录和xxxx.xcodeproj要在同一个目录，如果放到其他目录，请自行修改脚本。
#工程名字(Target名字)
Project_Name="JenkinsApp"
Workspace_Name=$Project_Name

#配置环境，Release或者Debug
Configuration="Debug"

#AdHoc版本的Bundle ID
AdHocBundleID="com.xxx"
#AppStore版本的Bundle ID
AppStoreBundleID="com.xxx"
#enterprise的Bundle ID
EnterpriseBundleID="com.zto.ztoFamily"

EnterpriseExportOptionsPlist=./fastlane/ExportOptions.plist

#pod install
ROOT_PATH="$PWD"
IPA_PATH="${ROOT_PATH}/Export/${Project_Name}"

echo $ROOT_PATH
echo $IPA_PATH

echo "~~~~~~~~~~~~选择打包方式(输入序号)~~~~~~~~~~~~~~~"
echo "  1 adHoc"
echo "  2 AppStore"
echo "  3 Enterprise"

# 读取用户输入并存到变量里
read parameter
sleep 0.5
method="$parameter"
echo "输入 $method"

xcodebuild -project $Workspace_Name.xcodeproj -scheme $Project_Name clean


xcodebuild -project $Workspace_Name.xcodeproj -scheme $Project_Name -configuration $Configuration -archivePath build/$Project_Name-enterprise.xcarchive archive build CODE_SIGN_STYLE="Automatic" DEVELOPMENT_TEAM="44J4M7A3TP"  PRODUCT_BUNDLE_IDENTIFIER="${EnterpriseBundleID}"


xcodebuild  -exportArchive -archivePath build/$Project_Name-enterprise.xcarchive -exportOptionsPlist ${EnterpriseExportOptionsPlist} -exportPath $IPA_PATH

echo "${IPA_PATH}/${Project_Name}.ipa"

步骤3-上传至蒲公英
PGYERLOG_PATH="${IPA_PATH}/upload_pgyer_log"
#创建蒲公英上传结果日志文件夹
mkdir -p ${PGYERLOG_PATH}
#创建蒲公英上传结果日志文
touch "${PGYERLOG_PATH}/log.txt"
#上传至蒲公英
curl -F "_api_key=f9074ad324f108637cdd2f113fdd79f3" -F "file=@${IPA_PATH}/${Project_Name}.ipa" https://www.pgyer.com/apiv2/app/upload 2>&1 | tee "${PGYERLOG_PATH}/log.txt"

echo "\033[36m使用AutoPackageScript打包总用时: ${SECONDS}s \033[0m"


